COUNTRY INFO PROGRAM:
I want to retrieve the country information using the 'countryinfo' library. I have installed countryinfo python package using pip.
pip install countryinfo
CODE:
To get country information and print basic country information using python, import CountryInfo,
from countryinfo import CountryInfo def get_country_info(country_name): try: country = CountryInfo(country_name) return { 'capital': country.capital(), "Region": country.region(), "Currencies": country.currencies(), "Languages": country.languages(), } except Exception as e: print(f"Error: {e}") if __name__ == "__main__": country_name = input("Enter the country name: ") country_details = get_country_info(country_name) print(country_details)
I got this following error while executing a python program.
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 49: character maps to <undefined>.
SOLUTION:
This problem is related to the character encoding. To handle this issue use encoding utf-8.
country_info = json.load(open(file_path,encoding='utf-8'))
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article